package halberd.data;

public class Complex {  
    public  final double re;   // the real part  
    public  final double im;   // the imaginary part  
  
    public Complex() {  
        re = 0;  
        im = 0;  
    }  
      
    public Complex(double real, double imag) {  
        re = real;  
        im = imag;  
    }  
  
    public String toString() {  
        if (im == 0) return re + "";  
        if (re == 0) return im + "i";  
        if (im <  0) return re + " - " + (-im) + "i";  
        return re + " + " + im + "i";  
    }  
  
    public double abs()   { return Math.hypot(re, im); }    
    public double phase() { return Math.atan2(im, re); }   
  
    public Complex conjugate() {  return new Complex(re, -im); }  

    public double re() { return re; }  
    public double im() { return im; }  
  
} 